package com.github.binarywang.demo.wx.mp.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;

@RestController
@Slf4j
public class AccessTokenController {

    @Autowired
    private WxMpService wxMpService;

    /**
     * https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Get_access_token.html
     */
    @RequestMapping("/getAccessToken")
    public Object getAccessToken() {
        try {
            return wxMpService.getAccessToken();
        } catch (WxErrorException e) {
            log.error("error", e);
            return e.toString();
        }
    }
}
